<?php
class ProgramacionsController extends AppController {

	var $name = 'Programacions';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		if($this->JQGridPaginate->isGrid){
			$fields = array('Programacion.id',
			'"Curso"."descripcion" AS "Programacion__curso"',
			'"Persona"."nombre_completo" AS "Programacion__persona"',
			'"Periodo"."anio" || \' - \' || "Periodo"."ciclo" AS "Programacion__periodo"',		
			'Programacion.seccion',
			'Programacion.fecha_inicio',
			'Programacion.fecha_fin',
			'Programacion.hora_inicio',
			'Programacion.hora_fin',
			'substr("Programacion"."semana",1,1) AS "Programacion__lunes"',	
			'substr("Programacion"."semana",2,1) AS "Programacion__martes"',
			'substr("Programacion"."semana",3,1) AS "Programacion__miercoles"',
			'substr("Programacion"."semana",4,1) AS "Programacion__jueves"',
			'substr("Programacion"."semana",5,1) AS "Programacion__viernes"',
			'substr("Programacion"."semana",6,1) AS "Programacion__sabado"',
			'substr("Programacion"."semana",7,1) AS "Programacion__domingo"',	
			'Programacion.created',
			'"Estado"."descripcion" AS "Programacion__estado"');			
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Programacion");
			$this->autoRender = false;
		}elseif($this->RequestHandler->isPost()){	
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
				$this->Programacion->create();				 
			}elseif ($oper == "edit"){
				$this->data['Programacion']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Programacion']['id'] = $this->params['form']['id'];
				$this->data['Programacion']['estado_id'] = 2;				
			}
			
			
			//Configure::write('debug',2);
			$this->data['Programacion']['semana']=$this->data['Programacion']['lunes'].$this->data['Programacion']['martes'].$this->data['Programacion']['miercoles'].$this->data['Programacion']['jueves'].$this->data['Programacion']['viernes'].$this->data['Programacion']['sabado'].$this->data['Programacion']['domingo'];
			@$this->Programacion->save($this->data['Programacion']);
			//pr($this->data);
			echo json_encode($this->Programacion->visualizarError($this->Programacion->validationErrors));
			$this->autoRender = false;
		}		
	}
	
	/*function listaProgramacions(){
		$this->layout="ajax";
		$listaProgramacions = $this->Programacion->find('list',array('fields'=>array('Programacion.id','Programacion.descripcion'),
															'order'=>'Programacion.descripcion'));
		echo json_encode($listaProgramacions);
		$this->autoRender = false;
	}*/
}